package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strings"
)

func main() {
	if len(os.Args) < 2 {
		fmt.Println("Usage: dedup.exe <file>")
		os.Exit(1)
	}
	f, err := os.Open(os.Args[1])
	if err != nil {
		os.Exit(1)
	}
	defer f.Close()
	m := make(map[string]int)
	reader := bufio.NewReader(f)
	for {
		str, err := reader.ReadString('\n')
		if err == io.EOF {
			break
		}
		cnt, ok := m[str]
		if ok {
			m[str] = cnt + 1
		} else {
			m[str] = 1
		}
	}

	for str, c := range m {
		fmt.Println(c, " ", strings.Trim(str, "\n"))
	}

	fmt.Println("the end")
}
